%!TEX program = xelatex
%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[12pt,t,aspectratio=169,mathserif]{beamer}
%Other possible values are: 1610, 149, 54, 43 and 32. By default, it is to 128mm by 96mm(4:3).
%run XeLaTeX to compile.

\input{wang-slides-preamble.tex}

\begin{document}

\title{第6章：多维图形}
%(1.1-1.2) 
%\institute{上海立信会计金融学院}
\author{JMS LQW}
%\date{2021年3月12日}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{frame}[fragile=singleslide]{6.1.1. }
\begin{frame}{目录 }

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{enumerate}
\item[6.1.]  概述 
\item[6.2.]  高维数据降为二维数据
\item[6.3.]  可视化软件
\item[6.4.]  可视化任务示例
\item[6.5.]  孤立波的可视化
\item[6.6.]  三维对象的可视化
\item[6.7.]  三维曲线
\item[6.8.]  简单曲面
\item[6.9.]  参数化定义的曲面
\item[6.10.] Julia 集合的可视化

\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.1. 概述}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：很多科学计算需要研究多元函数 $y = f(x_1,x_2,\cdots,x_p)$. 跟这个函数有关的数据会是什么样子的？
\item  答：

\begin{table}[ht]
\centering
\caption{结构化数据}
\begin{tabular}{|c|c|c|p{2cm}|c|}\hline 
应变量 & 自变量1 & 自变量2 & $\cdots$ & 自变量p  \\ \hline
$y_1$ & $x_{11}$ & $x_{21}$ & $\cdots$ & $x_{p1}$ \\ \hline 
$y_2$ & $x_{12}$ & $x_{22}$ & $\cdots$ & $x_{p2}$ \\ \hline 
$y_3$ & $x_{13}$ & $x_{23}$ & $\cdots$ & $x_{p3}$ \\ \hline 
$\vdots$ & $\vdots$  & $\vdots$ &  & $\vdots$  \\ \hline 
$y_n$ & $x_{1n}$ & $x_{2n}$ & $\cdots$ & $x_{pn}$ \\ \hline 
\end{tabular}
\end{table}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.2. 降维到二维 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：屏幕和纸张都是二维的。如何将三维或更高维的对象用二维数据来表示？什么是截面？什么是投影？

\begin{enumerate}
\item  截面：固定除两个变量之外的其余变量的值。例如考虑函数 
\begin{eqnarray*}
y &=& f(x_1,x_{20},x_{30}\cdots,x_{p0}), \\ 
y_0 &=& f(x_1,x_2,x_{30}\cdots,x_{p0}). 
\end{eqnarray*}

\item  投影：以三维空间投影到平面为例，设 $\vec{n}$ 是一个固定的单位向量，设 $\vec{n}$ 是平面 $\pi$ 的法向量。
设 $\vec{x}$ 是三维空间中的任意一个向量。则将 $\vec{x}$ 投影到平面 $\pi$ 的投影向量为
$P(\vec{x}) = \vec{x} - \langle \vec{x}, \vec{n}\rangle \vec{n}$. 

证明：因为 $\vec{n}$ 是单位向量，所以 $\langle \vec{x}, \vec{n}\rangle \vec{n}$ 是 $\vec{x}$ 在 $\vec{n}$ 方向的投影。
\begin{eqnarray*}
\langle P(\vec{x}),\vec{n}\rangle = \langle \vec{x} - \langle \vec{x}, \vec{n}\rangle \vec{n},\vec{n}\rangle 
= \langle \vec{x}, \vec{n}\rangle - \langle \vec{x}, \vec{n}\rangle \langle \vec{n},\vec{n}\rangle = 0.
\end{eqnarray*}

\end{enumerate}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.2. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：求向量 $\vec{x} = (1,2,3)$ 在平面 $3x+2y+6z=0$ 上的投影。

\item  答：
\begin{itemize}
\item  平面法向量为 $\vec{n} = (3,2,6)/\sqrt{9+4+36} = (3,2,6)/7$. 
\item  平面法向量与给定向量的内积为 $\langle \vec{x}, \vec{n} \rangle = (3+4+18)/7 = 25/7$. 
\item  给定向量在这个平面的投影为 
$$P(\vec{x}) = \vec{x} -  \langle \vec{x}, \vec{n} \rangle \vec{n} = (1,2,3) - 25(3,2,6)/49=(-26,48,-3)/49. $$ 

\end{itemize}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.2. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-6-2.png}
% \caption{ }
\end{figure}


\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.3. 可视化软件 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：可视化软件的标准数据格式有哪些？
\begin{itemize}
\item  \url{https://www.hdfgroup.org}
\item  \url{https://vtk.org}
\end{itemize}

\item  问：可视化软件包的任务是什么？
\begin{itemize}
\item  以指定格式获取数据并生成二维视图。
\end{itemize}

\item  问：现有的可视化软件包有哪些？
\begin{itemize}
\item  \url{https://docs.enthought.com/mayavi/mayavi/}
\item  \url{http://mayavi.sourceforge.net}
\item  \url{https://www.paraview.org}
\item  \url{https://hpc.llnl.gov/software/visualization-software/visit}
\end{itemize}

\end{itemize}

\end{frame}


%https://www.llnl.gov/about
%
%For more than 60 years, the Lawrence Livermore National Laboratory has applied science and technology to make the world a safer place.
%
%Our Values
%
%Ideas. Livermore is the “new ideas” laboratory, and we continue to aspire to intellectual leadership, originality, and audacity. We support an environment that encourages open exchange and critique. Ideas also improve operations and lead to new, better ways of doing business.
%
%Impact. Innovation happens when new ideas have impact—on our mission, on people’s lives. Ultimately, our success depends on applying frontier science and technology, through disciplined engineering, to deliver solutions for—have impact on—our mission.
%
%Integrity. We serve the public interest and act to sustain the public trust through transparency, honesty, and objectivity. We act ethically in our research activities, our business practices, and our interactions with each other. We are dedicated to collective success, and committed to safety and security as an integral part of the mission.
%
%Inclusiveness. The challenges of our mission demand that we draw on the widest possible diversity of talents, thought, and experiences. To capitalize on the range of individual and diverse talents needed for mission success, we form and work in teams, characterized by mutual respect and support.
%
%Zeal. It’s good to love what you do. We value enthusiasm for and commitment to the Lab’s mission. We have a “fire in the belly” to excel, lead, and change the world. And as an institution, the Lab will aspire to be a place where people can find fulfillment and love their work. 
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.4. 可视化任务示例 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：在现实问题中，需要可视化的数据来自哪里？
\begin{itemize}
\item  实验。
\item  数值逼近。
\end{itemize}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5. 孤立波的可视化 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问： Korteweg - de Vries 方程是一个非线性波动方程 $$u_t + u_{xxx} + 6uu_x = 0.$$
验证下述被称为孤立波的函数是这个方程的一个解：
$$u(t,x,c) = \frac{c}{2 \cosh^2 (\sqrt{c}(x-ct)/2) }.$$

\item  问： 为了将孤立波可视化，下述三种思路的区别是什么？
\begin{enumerate}
\item  交互式操作。
\item  动画。
\item  电影。
\end{enumerate}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5. hyperbolic cosine and hyperbolic secant }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  双曲余弦函数，以及倒数：
$$\text{cosh}(x)=\frac{e^x+e^{-x}}{2}, \,\,\, \text{sech}(x) = \frac{1}{\text{cosh}(x)}. $$

\end{itemize}


\begin{figure}
\centering
\includegraphics[height=0.4\textheight, width=0.7\textwidth]{pic/fig-6-5.png}
% \caption{ }
\end{figure}


\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5. Korteweg - de Vries Equation -- by wikipedia}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item   In mathematics, the Korteweg - De Vries (KdV) equation is a mathematical model of waves on shallow water surfaces. 

\item   It is particularly notable as the prototypical example of an exactly solvable model, that is, a non-linear partial differential equation whose solutions can be exactly and precisely specified. 

\item   KdV can be solved by means of the inverse scattering transform. 

\item   The mathematical theory behind the KdV equation is a topic of active research. 

\item   The KdV equation was first introduced by Boussinesq (1877) and rediscovered by Diederik Korteweg and Gustav de Vries (1895).

\end{itemize}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5. Boussinesq, Korteweg and de Vries }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.6\textheight, width=0.27\textwidth]{pic/joseph-valentin-boussinesq.png}
\hspace{0.3cm}
\includegraphics[height=0.6\textheight, width=0.27\textwidth]{pic/diederik-johannes-korteweg.png}
\hspace{0.3cm}
\includegraphics[height=0.6\textheight, width=0.27\textwidth]{pic/gustav-de-vries.png}
% \caption{ }
\end{figure}


\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.1. 交互式操作任务 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：阅读 Matplotlib 官网的例子，实现孤立波的交互式显示。

\begin{python}
%matplotlib notebook
#%matplotlib inline
\end{python}

\item  答：使用Jupyter Notebook, 运行文件：6-多维图形.ipynb.

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码1/4: 

\begin{python}
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button

def solwave(x,t,c):
    temp=np.cosh(np.sqrt(c)*(x-c*t)/2)
    return c/(2*temp**2)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码2/4: 

\begin{python}
fig,ax=plt.subplots()
plt.subplots_adjust(left=0.15,bottom=0.30)
plt.xlabel('x')
plt.ylabel('y')
x=np.linspace(-5.0,20.0,1001)
t0=5.0
c0=1.0
line,=plt.plot(x,solwave(x,t0,c0),lw=2,color='blue')
plt.axis([-5,20,0,2])

axcolor='lightgoldenrodyellow'
axtime=plt.axes([0.20,0.15,0.65,0.03],facecolor=axcolor)
axvely=plt.axes([0.20,0.10,0.65,0.03],facecolor=axcolor)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码3/4: 

\begin{python}
stime=Slider(axtime,'Time',0.0,20.0,valinit=t0)
svely=Slider(axvely,'Vely',0.1,3.0,valinit=c0)

def update(val):
    time=stime.val
    vely=svely.val
    line.set_ydata=solwave(x,time,vely)
    fig.canvas.draw_idle()
    
svely.on_changed(update)
stime.on_changed(update)
\end{python}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码4/4: 

\begin{python}
resetax=plt.axes([0.75,0.025,0.1,0.04])
button=Button(resetax,'Reset',color=axcolor,
              hovercolor='0.975')
    
def reset(event):
    svely.reset()
    stime.reset()
    
button.on_clicked(reset)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-6-5-1.png}
% \caption{ }
\end{figure}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.2. 动画任务 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用附加模块 JSAnimation, 实现孤立波的动画。

\item  问：使用 matplotlib 的 animation 子模块，实现孤立波的动画。

\url{https://matplotlib.org/stable/gallery/index.html#animation}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.2. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码1/3: 

\begin{python}
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def solwave(x,t,c=1):
    temp=np.cosh(np.sqrt(c)*(x-c*t)/2)
    return c/(2*temp**2)

fig=plt.figure()
ax=plt.axes(xlim=(-5,20),ylim=(0,0.6))
line, = ax.plot([],[],lw=2)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.2. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码2/3: 

\begin{python}
t=np.linspace(-10,25,91)
x=np.linspace(-5,20.0,101)

def init():
    line.set_data([],[])
    return line,

def animate(i):
    y=solwave(x,t[i])
    line.set_data(x,y)
    return line,
\end{python}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.2. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码3/3: 

\begin{python}
ani=animation.FuncAnimation(fig, animate, init_func=init, 
                    frames=90, interval=30, blit=True)
plt.show()

writer = animation.FFMpegWriter(
    fps=15, metadata=dict(artist='Me'), bitrate=1800)
ani.save("movie.mp4", writer=writer)
\end{python}


\item  查看文件：movie.mp4.

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.5.3. 电影任务 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：研究 ffmpeg 软件包，用电影方式显示孤立波。

\url{https://ffmpeg.org}

\item  FFmpeg is the leading multimedia framework, able to decode, encode, transcode, mux, demux, stream, filter and play pretty much anything that humans and machines have created. It supports the most obscure ancient formats up to the cutting edge. No matter if they were designed by some standards committee, the community or a corporation. 

\item  It is also highly portable: FFmpeg compiles, runs, and passes our testing infrastructure FATE across Linux, Mac OS X, Microsoft Windows, the BSDs, Solaris, etc. under a wide variety of build environments, machine architectures, and configurations.


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.6. 三维对象的可视化 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：如何使用 Python 画出下述几类三维图像？
\begin{enumerate}
\item  参数化曲线：$(x(t), y(t), z(t))$. 
\item  曲面： $z=z(x,y)$.
\item  参数化曲面：$x=x(u,v), y=y(u,v), z=z(u,v)$. 
\end{enumerate}

\item  问：有哪些两种不同的软件包来画三维图像？
\begin{enumerate}
\item   Matplotlib 的 mplot3d 模块。
\item  Mayavi 的 mlab 模块。
\end{enumerate}


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.7.1. 使用 mplot3d 可视化曲线 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：画出三维曲线
\begin{eqnarray*}
x &=& (1+a\cos(nt))\cos(mt), \\
y &=& (1+a\cos(nt))\sin(mt), \\
z &=& a\sin(nt).
\end{eqnarray*}
其中 $t\in [0,2\pi]$. 常量 $a, m, n$ 可以自己设定。

\end{itemize}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.7.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码1/2: 

\begin{python}
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

theta=np.linspace(0,2*np.pi,101)
a=0.3; m=11; n=9

x=(1+a*np.cos(n*theta))*np.cos(m*theta)
y=(1+a*np.cos(n*theta))*np.sin(m*theta)
z=a*np.sin(n*theta)
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.7.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  代码2/2: 

\begin{python}
fig=plt.figure()
ax=Axes3D(fig)
ax.plot(x,y,z,'g',linewidth=2)
ax.set_zlim3d(-1.0,1.0)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('A spiral as a parametric curve',
         weight='bold',size=16)
ax.elev, ax.azim = 60, -120
fig.savefig('pic/fig-6-7-1.png')
\end{python}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.7.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.9\textwidth]{pic/fig-6-7-1.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.7.2. 使用 mlab 可视化曲线 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用 mayavi 模块的 mlab 画出上一节的三维曲线。


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.8.1. 使用 mplot3d 可视化简单曲面 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用 mplot3d 的 Axes3D 对象，画出下述二元函数定义的曲面
$$z = e^{-2x^2-y^2} \cos(2x)\cos(3y), \,\, -2\le x\le 2, -3\le y\le 3. $$

\end{itemize}

\begin{python}
import numpy as np

xx,yy=np.mgrid[-2:2:81j,-3:3:91j]
zz=np.exp(-2*xx**2-yy**2)*np.cos(2*xx)*np.cos(3*yy)

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig=plt.figure()
ax=Axes3D(fig)
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.8.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
ax.plot_surface(xx,yy,zz,rstride=4,cstride=3,
                color='c',alpha=0.9)
ax.contour(xx,yy,zz,zdir='x',offset=-3.0,color='black')
ax.contour(xx,yy,zz,zdir='y',offset=4.0,color='blue')
ax.contour(xx,yy,zz,zdir='z',offset=-2.0)
ax.set_xlim3d(-3.0,2.0)
ax.set_ylim3d(-3.0,4.0)
ax.set_zlim3d(-2.0,1.0)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
fig.savefig('pic/fig-6-8-1.png')
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.8.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.9\textwidth]{pic/fig-6-8-1.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.8.2. 使用 mlab 可视化简单曲面 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用 mayavi 模块的 mlab 画出上一节的曲面。


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.9.1. 使用 mplot3d 可视化 Enneper 曲面 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用 matplotlib 模块的 Axes3D 对象，画出参数化的曲面：
\begin{eqnarray*}
x &=& u(1-u^3/3+v^2), \\
y &=& v(1-v^2/3+u^2), \\
z &=& u^2-v^2.
\end{eqnarray*}
其中 $-2\le u,v\le 2$. 

\end{itemize}

\begin{python}
import numpy as np
[u,v]=np.mgrid[-2:2:51j,-2:2:61j]
x,y,z=u*(1-u**2/3+v**2),v*(1-v**2/2+u**2),u**2-v**2

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.9.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{python}
fig=plt.figure()
ax=Axes3D(fig)
ax.plot_surface(x.T,y.T,z.T,rstride=2,cstride=2,
    color='blue',alpha=0.5,linewidth=0.5)

ax.elev,ax.azim=50,-80
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('Enneper surface plot',
             weight='bold',size=14)
fig.savefig('pic/fig-6-9-1.png') 
\end{python}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.9.1. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.9\textwidth]{pic/fig-6-9-1.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.9.2. 使用 mlab 可视化 Enneper 曲面 }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：使用 mayavi 模块的 mlab 画出上一节的曲面。


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.10. Julia 集的三维可视化}
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}\itemsep1em

\item  固定一个复数 $c$, 其模长小于2. 定义 Julia 集合 $J(c)$ 为满足如下条件的复数 $z_0$ 组成的集合：
数列 $\{ z_0, z_{n+1} = z_n^2+c, n\ge 0\}$ 是有界的。

\item  对每个复数 $z_0$, 定义它的逃逸参数 $\varepsilon(z_0)$ 为使得 $z_n$ 的模长大于 2 的最小整数 $n$. 
如果 $z_0$ 属于 Julia 集合 $J(c)$, 则定义它的逃逸参数为 $\infty$. 

\item  问：选取一个复数 $c$, 其模长小于2. 选取让 $z_0$ 取值的一个矩形区域。画出这个区域中的（某个网格上的）所有复数的逃逸参数形成的图像。使用 mayavi 画出峡谷视图。

\item  查看 mayavi 的官网。\url{https://docs.enthought.com/mayavi/mayavi/}

\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.10. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  问：修改下述代码，使能处理 $z$ 的模长为无穷大的情形。 

\begin{python}
import numpy as np

x,y=np.mgrid[-1.5:1.0:1000j,-1.0:1.0:1000j]
z=x+1j*y
julia=np.zeros(z.shape)
c=-0.7-0.4j

for it in range(1,101):
    z=z*z+c
    escape=z*z.conjugate()>4
    julia+=(1/float(it))*escape

import matplotlib.pyplot as plt
plt.imshow(julia)
\end{python}

\end{itemize}


\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.10. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{figure}
\centering
\includegraphics[height=0.7\textheight, width=0.7\textwidth]{pic/fig-6-10.png}
% \caption{ }
\end{figure}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile=singleslide]{6.11. }
%\begin{frame}{}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{itemize}

\item  练习：在解析几何的教材里，找一些曲面画出图形。


\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{frame}[fragile=singleslide]{1.20. }
\begin{frame}{参考文献}

\vspace{-0.4cm}\noindent\makebox[\linewidth]{\rule{\paperwidth}{0.4pt}}
%每页详细内容

\begin{thebibliography}{99}
\bibitem{stewart-en} John M. Stewart. \emph{Python for Scientists}. Second Edition. Cambridge University Press. 2017. 
\bibitem{stewart-cn} 约翰.M.斯图尔特(著). 江红等(译). \emph{Python科学计算}，机械工业出版社，2019年8月第1版。
\bibitem{klaus-brauer-kdv} Klaus Brauer. \emph{The Korteweg-de Vries Equation: History, exact solution, and graph representation.} May 2000. 
\bibitem{nicolas-schalch-kdv} Nicolas Schalch. \emph{The Korteweg-de Vries Equation}. Proseminar, ETH Zurich. March 2018.

\end{thebibliography}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}


